# 基于官方 Node.js 镜像构建
FROM node:18.14.2-alpine3.17 AS build

# 设置工作目录
WORKDIR /app

# 复制 package.json 和 package-lock.json
COPY package.json .
# COPY package-lock.json .

# 测试信息
RUN echo "当前路径: $(pwd)"
RUN echo "当前目录列表: $(ls)"
RUN echo "node版本: $(node -v)"
RUN echo "yarn版本: $(yarn -v)"

# 安装依赖
RUN yarn install --registry=https://registry.npm.taobao.org

# 复制源代码
COPY . .
#COPY dist/ . 测试推送cc

RUN echo "当前路径: $(pwd)"
RUN echo "当前目录列表: $(ls)"

# 构建生产环境代码
RUN yarn build

# 基于 Nginx 镜像构建
FROM nginx:1.21-alpine

# 拷贝构建结果到 Nginx 静态资源目录
COPY --from=build /app/dist /usr/share/nginx/html

# 拷贝 Nginx 配置文件到容器
COPY ./nginx.conf /etc/nginx/nginx.conf

# 暴露容器端口
EXPOSE 80

# 启动 Nginx 服务器
CMD ["nginx", "-g", "daemon off;"]